package com.yxhl.zoume.common.presenter;

import android.content.Context;

import com.yxhl.zoume.common.ui.view.BaseView;
import com.yxhl.zoume.common.ui.view.PerfectCouponView;
import com.yxhl.zoume.data.http.model.coupon.CouponInfo;
import com.yxhl.zoume.data.http.rest.param.busticket.PerfectCouponParam;
import com.yxhl.zoume.data.http.rest.response.coupon.PerfectCouponResponse;
import com.yxhl.zoume.domain.interactor.ZMSubscriber;
import com.yxhl.zoume.domain.interactor.coupon.PerfectCouponUseCase;

import javax.inject.Inject;

/**
 * 项目名称：Ferrari
 * Created by menggod on 16/11/10 .
 */

public class PerfectCouponPresenter extends BasePresenter implements IPresenter {

    private PerfectCouponView mCouponView;

    @Inject
    PerfectCouponUseCase mPerfectCouponUseCase;

    @Inject
    public PerfectCouponPresenter(Context context) {
        super(context);
    }

    public void queryPerfectCoupon(int typeNumber ,double totalAmount ,String couponUserId){
        PerfectCouponParam perfectCouponParam = new PerfectCouponParam();
        perfectCouponParam
                .setCouponUserRelId(couponUserId)
                .setBizType(typeNumber)
                .setOrderTotalFee(String.valueOf(totalAmount))
                .setToken(getToken())
                .setMobile(getMobile());

        mPerfectCouponUseCase.execute(perfectCouponParam, new ZMSubscriber<PerfectCouponResponse>(){
            @Override
            public void onCompleted() {
                super.onCompleted();
            }

            @Override
            public void onError(Throwable e) {
                super.onError(e);
            }

            @Override
            public void onNext(PerfectCouponResponse response) {
                super.onNext(response);
                if (null!=response){
                    boolean isSuccess = response.isSucc();
                    if (isSuccess){
                        CouponInfo perfectCoupon = response.getPerfectCoupon();
                        mCouponView.renderPerfectCouponSuccess(response.getPerfectCoupon());
                    }else {
                        mCouponView.renderPerfectCouponFailure();
                    }
                }

            }
        });

    }
    @Override
    public void attachView(BaseView view) {
        mCouponView = (PerfectCouponView) view;

    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        mPerfectCouponUseCase.unsubscribe();
    }
}
